<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var names = ["abc", "cba", "nba", "mba"]
    var name = names.find(function (item) {
      if (item === "mba") return true
    })
    console.log(name)

    var students = [
      { id: 100, name: 'why', age: 18 },
      { id: 101, name: 'kobe', age: 30 },
      { id: 102, name: 'james', age: 25 },
      { id: 103, name: 'why1', age: 22 },
    ]
    var stu = students.find(item => item.id === 101)
    console.log(stu)

    Array.prototype.hyFind = function (fn) {
      for (var i = 0; i < this.length; i++) {
        var isFlag = fn(this[i], i, this)
        if (isFlag) {
          return this[i]
        }
      }
      return undefined
    }
    var stu1 = students.hyFind(item => item.id === 101)
    var stu2 = students.hyFind(item => item.id === 110)
    console.log(stu1)
    console.log(stu2)


  </script>
</body>

</html>